{% extends "base.html" %}
{% load i18n %}
{% load difftags %}
{% load djblets_deco %}
{% load djblets_utils %}
{% load djblets_js %}
{% load reviewtags %}

{% block title %}{{review_request_details.summary}} | {% trans "Review Request" %}{% endblock %}
{% block extrahead %}
<meta content="no-cache" http-equiv="pragma" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/diffviewer.css" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/reviews.css" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/syntax.css" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/yui-ui.css" />
<script type="text/javascript" src="{{MEDIA_URL}}yui/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/animation/animation-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/connection/connection-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/event/event-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/dom/dom-min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui/utilities/utilities.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}yui-ext/yui-ext.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/scripts/rb/common.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/scripts/rb/dialogs.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/scripts/rb/widgets.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/scripts/reviews.js"></script>
<script type="text/javascript">
  var gReviewRequestPath = '{{review_request.get_absolute_url}}';
  var gUserURL = "{% url user user %}";
{% if not user.is_anonymous %}
  var gUserFullName = "{{user|user_displayname}}";
{% endif %}
  var gReviewRequestId = "{{review_request.id}}";
  var gBugTrackerURL = "{{review_request.repository.bug_tracker}}";
</script>
{% endblock %}

{% block content %}
{% ifneatnumber review_request.id %}
{%  box "yay" %}
 <img src="{{MEDIA_URL}}rb/images/{% if milestone %}trophy{% else %}fish-trophy{% endif %}.png" width="32" height="48" border="0" alt="" />
 <h1>{{review_request.submitter|user_displayname}} got review request #{{review_request.id}}!</h1>
{%  endbox %}
{% endifneatnumber %}

{% include "reviews/review_header.html" %}

{% box "review-request" %}
<ul id="topcontrols">
{% if review_request_details.diffset or review_request.diffset_history.diffsets.count %}
 <li><a href="diff/#index_header"><img src="{{MEDIA_URL}}rb/images/diff.png" width="17" height="14" border="0" alt="" /> {% trans "View Diff" %}</a></li>
{% endif %}
</ul>
<div class="main">
{% include "reviews/review_request_box.html" %}
</div>
<ul class="controls">
{% if perms.reviews.delete_reviewrequest %}
 <li><a id="delete-review-request-link" href="#" onClick="deleteReviewRequest();"><img src="{{MEDIA_URL}}rb/images/delete.png" width="12" height="12" border="0" alt="" /> {% trans "Delete" %}</a></li>
{% endif %}
{% ifuserorperm review_request.submitter "reviews.can_change_status" %}
{%  if review_request.public %}
{%    ifequal review_request.status 'P' %}
 <li><a href="{{review_request.get_absolute_url}}submitted/">{% trans "Set Submitted" %}</a></li>
 <li><a href="#" onClick="discardReviewRequest();" id="discard-review-request-link">{% trans "Discard" %}</a></li>
{%    endifequal %}
{%  endif %}
{% endifuserorperm %}
{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
 <li><a id="upload-diff-link" href="#" onClick="RB.dialogs.showFormDialog('upload-diff-link');"><img src="{{MEDIA_URL}}rb/images/upload.png" width="14" height="14" border="0" alt="" /> {% if review_request_details.diffset or review_request.diffset_history.diffsets.count %} {% trans "Update Attached Diff" %}{% else %} {% trans "Attach Diff" %}{% endif %}</a></li>
 <li><a id="upload-screenshot-link" href="#" onClick="RB.dialogs.showFormDialog('upload-screenshot-link');"><img src="{{MEDIA_URL}}rb/images/upload.png" width="14" height="14" border="0" alt="" /> {% trans "Attach Screenshot" %}</a></li>
{% endifuserorperm %}
{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
 <noscript><li><a href="{{review_request.get_absolute_url}}edit/"><img src="{{MEDIA_URL}}rb/images/edit.png" width="14" height="14" border="0" alt="" /> {% trans "Edit" %}</a></li></noscript>
{% endifuserorperm %}
</ul>
{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
<script type="text/javascript">
  RB.dialogs.registerFormDialog("upload-diff-link", {
    title: "{% trans "Attach Diff" %}",
    confirmButton: "{% trans "Attach" %}",
    width: 400,
    height: 250,
    path: '{{SITE_ROOT}}api/json/reviewrequests/{{review_request.id}}/diff/new/',
    upload: true,
    onSubmitted: function() { window.location.reload(); },
    fields: {% form_dialog_fields upload_diff_form %}
  });

  RB.dialogs.registerFormDialog("upload-screenshot-link", {
    title: "{% trans "Attach Screenshot" %}",
    confirmButton: "{% trans "Attach" %}",
    width: 350,
    height: 250,
    path: '{{SITE_ROOT}}api/json/reviewrequests/{{review_request.id}}/screenshot/new/',
    upload: true,
    onSubmitted: function() { window.location.reload(); },
    fields: {% form_dialog_fields upload_screenshot_form %}
  });
</script>
{% endifuserorperm %}
{% endbox %}

{% for entry in entries %}
{%  if entry.review %}
<a name="review{{entry.review.id}}"></a>
{%   if forloop.last %}
<a name="last-review" />
{%   endif %}
{%   box "review" %}
<div class="main">
 <div id="{{entry.review.id}}-banners"></div>
 <div class="header">
  {% if entry.review.ship_it %}<div class="shipit">{% trans "Ship it!" %}</div>{% endif %}
  <div class="reviewer"><a href="{% url user entry.review.user %}">{{entry.review.user|user_displayname}}</a></div>
  <div class="posted_time">{% blocktrans with entry.review.timestamp|timesince as timestamp_since  and entry.review.timestamp|date:"F jS, Y, P" as timestamp_date %}Posted {{ timestamp_since }} ago ({{ timestamp_date }}){% endblocktrans %}</div>
 </div>
 <div class="body">
   <pre class="body_top">{{entry.review.body_top|escape}}</pre>
   {% reply_section entry.review "" "body_top" "rcbt" %}
{% if entry.review.comments.all or entry.review.screenshot_comments.all %}
   <dl class="diff-comments">
{% for comment in entry.review.screenshot_comments.all %}
    <dt>
     <a name="scomment{{comment.id}}"></a>
     <div class="screenshot">
      <span class="filename">
       <a href="{{comment.screenshot.get_absolute_url}}">{% if comment.screenshot.caption %}{{comment.screenshot.caption}}{% else %}{{comment.screenshot.image.name|basename}}{% endif %}</a>
      </span>
      {{comment.image|safe}}
     </div>
    </dt>
    <dd>
     <pre>{{comment.text|escape}}</pre>
     {% reply_section entry.review comment "screenshot_comment" "rc" %}
    </dd>
{% endfor %}
{% for comment in entry.review.ordered_comments %}
    <dt>
     <a name="comment{{comment.id}}"></a>
     <table class="sidebyside{% ifequal comment.filediff.source_revision PRE_CREATION %} newfile{% endifequal %}">
      <colgroup>
       <col class="line" />
       <col class="left" />
       <col class="line" />
       <col class="right" />
      </colgroup>
      <thead>
       <tr>
        <th colspan="4" class="filename">
         <a href="{{comment.get_absolute_url}}">{{comment.filediff.dest_file}}</a>
		 <span class="diffrevision">
{% if comment.interfilediff %}
          (Diff revisions {{comment.filediff.diffset.revision}} - {{comment.interfilediff.diffset.revision}})
{% else %}
		  (Diff revision {{comment.filediff.diffset.revision}})
{% endif %}
		 </span>
        </th>
       </tr>
      </thead>
{% forchunkswithlines comment.filediff comment.interfilediff comment.first_line comment.num_lines %}
      <tbody class="{{chunk.change}}">
{% for line in chunk.lines %}
       <tr{% ifnotequal chunk.change "equal" %}{% attr "class" %}{% if forloop.first %}first{% endif %} {% if forloop.last %}last{% endif %}{% endattr %}{% endifnotequal %}>
         <th>{{line.1}}</td>
         <td><pre>{{ line.2|highlightregion:line.3|showextrawhitespace }}</pre></td>
         <th>{{line.4}}</td>
         <td><pre>{{ line.5|highlightregion:line.6|showextrawhitespace }}</pre></td>
       </tr>
{% endfor %}
      </tbody>
{% endforchunkswithlines %}
     </table>
    </dt>
    <dd>
     <table>
      <tr>
       <td><strong>Type:</strong></td>
       <td>{{ comment.get_type_display }}</td>
      </tr>
      <tr>
       <td><strong>Phase originated:</strong></td>
       <td>{{ comment.get_phase_originated_display }}</td>
      </tr>
     </table>
     <pre>{{comment.text|escape}}</pre>
	 {% reply_section entry.review comment "comment" "rc" %}
    </dd>
{% endfor %}
   </dl>
{% endif %}
  {% if entry.review.body_bottom %}
   <pre class="body_bottom">{{entry.review.body_bottom|escape}}</pre>
   {% reply_section entry.review "" "body_bottom" "rcbb" %}
  {% endif %}
 </div>
</div>
{%   endbox %}
{%  endif %}
{%  if entry.changedesc %}
<a name="changedesc{{entry.changedesc.id}}"></a>
{%   box "changedesc" %}
<div class="main">
 <div class="header">
   <b>Review request changed</b>
   <div class="posted_time">{% blocktrans with entry.changedesc.timestamp|timesince as timestamp_since and entry.changedesc.timestamp|date:"F jS, Y, P" as timestamp_date %}Updated {{ timestamp_since }} ago ({{ timestamp_date }}){% endblocktrans %}</div>
 </div>
 <div class="body">
  <ul>
{% for fieldinfo in entry.changeinfo %}
   <li><label>{{fieldinfo.title}}</label>
{%  ifequal fieldinfo.type "changed" %}
{% blocktrans with fieldinfo.info.old.0 as old_value and fieldinfo.info.new.0 as new_value %}changed from <i>{{old_value}}</i> to <i>{{new_value}}</i>{% endblocktrans %}</p>
{%  endifequal %}
{%  ifequal fieldinfo.type "add_remove" %}
    <ul>
{%   if fieldinfo.info.removed %}
{% definevar "removed_values" %}
{% for item in fieldinfo.info.removed %}{% if item.1 %}<a href="{{item.1}}">{{item.0}}</a>{% else %}{{item.0}}{% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
{% enddefinevar %}
<li>{% blocktrans %}removed {{removed_values}}{% endblocktrans %}</li>
{%   endif %}
{%   if fieldinfo.info.added %}
{% definevar "added_values" %}
{% for item in fieldinfo.info.added %}{% if item.1 %}<a href="{{item.1}}">{{item.0}}</a>{% else %}{{item.0}}{% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
{% enddefinevar %}
<li>{% blocktrans %}added {{added_values}}{% endblocktrans %}</li>
{%   endif %}
    </ul>
{%  endifequal %}
{%  ifequal fieldinfo.type "screenshot_captions" %}
    <ul>
{%   for info in fieldinfo.info.values %}
     <li>{% blocktrans with info.old.0 as old_value and info.new.0 as new_value %}changed from <i>{{old_value}}</i> to <i>{{new_value}}</i>{% endblocktrans %}</li>
{%   endfor %}
    </ul>
{%  endifequal %}
   </li>
{% endfor %}
  </ul>
{% if entry.changedesc.text %}
  <label>{% trans "Description:" %}</label>
  <pre class="changedesc-text">{{entry.changedesc.text|escape}}</pre>
{% endif %}
 </div>
</div>
{%   endbox %}
{%  endif %}
{% endfor %}

{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
{% ifequal review_request.status 'P' %}
<script type="text/javascript">
  registerEditor('summary', false);
  registerEditor('branch', false);
  registerEditor('description', true);
  registerEditor('testing_done', true);
  registerCommaListEditor('bugs_closed', onBugsChanged);
  registerAutoCompleteCommaListEditor('target_groups',
                                      onTargetGroupsChanged,
                                      "{{SITE_ROOT}}api/json/groups/",
                                      ["groups", "name"]);
  registerAutoCompleteCommaListEditor('target_people',
                                      onTargetPeopleChanged,
                                      "{{SITE_ROOT}}api/json/users/",
                                      ["users", "username"]);

{% for image in review_request_details.screenshots.all %}
  registerEditor('screenshot_{{image.id}}_caption', false);
{% endfor %}

{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
{%  if review_request.public %}
    registerEditor('changedescription', true, true);
{%  endif %}
{% endifuserorperm %}
</script>
{% endifequal %}
{% endifuserorperm %}
{% endblock %}
